#include "stdafx.h"
#include "KeyMapping.h"


static KeyValuePair<EKey, USHORT> KeyMapping[] =
{
	{eKey_Unknown, 0},

	{eKey_LShift, VK_LSHIFT},
	{eKey_RShift, VK_RSHIFT},
	{eKey_LCtrl, VK_LCONTROL},
	{eKey_RCtrl, VK_RCONTROL},
	{eKey_LAlt, VK_LMENU},
	{eKey_RAlt, VK_RMENU},

	{eKey_Esc, VK_ESCAPE},
	{eKey_Tab, VK_TAB},
	{eKey_Backspace, VK_BACK},
	{eKey_Enter, VK_RETURN},
	{eKey_Space, VK_SPACE},

	{eKey_Insert, VK_INSERT},
	{eKey_Delete, VK_DELETE},
	{eKey_Home, VK_HOME},
	{eKey_End, VK_END},
	{eKey_PageDown, VK_NEXT},
	{eKey_PageUp, VK_PRIOR},

	{eKey_NumLock, VK_NUMLOCK},
	{eKey_CapsLock, VK_CAPITAL},
	{eKey_ScrollLock, VK_SCROLL},
	{eKey_Pause, VK_PAUSE},

	{eKey_Left, VK_LEFT},
	{eKey_Right, VK_RIGHT},
	{eKey_Up, VK_UP},
	{eKey_Down, VK_DOWN},

	{eKey_Tilde, VK_OEM_3},
	{eKey_Dot, VK_OEM_PERIOD},
	{eKey_Comma, VK_OEM_COMMA},
	{eKey_Minus, VK_OEM_MINUS},
	{eKey_Plus, VK_OEM_PLUS},
	{eKey_Semicolon, VK_OEM_1},
	{eKey_Quote, VK_OEM_7},

	{eKey_ForwardSlash, VK_OEM_2},
	{eKey_BackSlash, VK_OEM_5},
	{eKey_LBracket, VK_OEM_4},
	{eKey_RBracket, VK_OEM_6},

	{eKey_F1, VK_F1},
	{eKey_F2, VK_F2},
	{eKey_F3, VK_F3},
	{eKey_F4, VK_F4},
	{eKey_F5, VK_F5},
	{eKey_F6, VK_F6},
	{eKey_F7, VK_F7},
	{eKey_F8, VK_F8},
	{eKey_F9, VK_F9},
	{eKey_F10, VK_F10},
	{eKey_F11, VK_F11},
	{eKey_F12, VK_F12},

	{eKey_Num1, '1'},
	{eKey_Num2, '2'},
	{eKey_Num3, '3'},
	{eKey_Num4, '4'},
	{eKey_Num5, '5'},
	{eKey_Num6, '6'},
	{eKey_Num7, '7'},
	{eKey_Num8, '8'},
	{eKey_Num9, '9'},
	{eKey_Num0, '0'},

	{eKey_A, 'A'},
	{eKey_B, 'B'},
	{eKey_C, 'C'},
	{eKey_D, 'D'},
	{eKey_E, 'E'},
	{eKey_F, 'F'},
	{eKey_G, 'G'},
	{eKey_H, 'H'},
	{eKey_I, 'I'},
	{eKey_J, 'J'},
	{eKey_K, 'K'},
	{eKey_L, 'L'},
	{eKey_M, 'M'},
	{eKey_N, 'N'},
	{eKey_O, 'O'},
	{eKey_P, 'P'},
	{eKey_Q, 'Q'},
	{eKey_R, 'R'},
	{eKey_S, 'S'},
	{eKey_T, 'T'},
	{eKey_U, 'U'},
	{eKey_V, 'V'},
	{eKey_W, 'W'},
	{eKey_X, 'X'},
	{eKey_Y, 'Y'},
	{eKey_Z, 'Z'},
};
	
CKeyMapping::CKeyMapping()
{
	uint size = sizeof(KeyMapping)/sizeof(KeyMapping[0]);
	for (uint i = 0; i < size; ++i)
	{
		USHORT vkey = KeyMapping[i].val;
		EKey key = KeyMapping[i].key;
		m_keymap[vkey] = key;
	}
}	
	
EKey CKeyMapping::MapVirtualKey(USHORT vkey) const
{
	return stl::find_in_map(m_keymap, vkey, eKey_Unknown);
}